package top.carrotguo.weibo.utils;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.w3c.dom.Text;

import butterknife.BindInt;
import butterknife.BindView;
import butterknife.ButterKnife;
import top.carrotguo.weibo.R;

public class TitlebarBuilder {

    View mRootView;
    TextView tvLeft;
    ImageView ivLeft;
    TextView tvCenter;
    TextView tvRight;
    ImageView ivRight;

    public TitlebarBuilder(Activity context){
        mRootView = context.findViewById(R.id.title_root);
        tvLeft = context.findViewById(R.id.tv_left);
        tvRight = context.findViewById(R.id.tv_right);
        ivLeft = context.findViewById(R.id.iv_left);
        ivRight = context.findViewById(R.id.iv_right);
        tvCenter = context.findViewById(R.id.tv_title);
    }

    public TitlebarBuilder setCenterTitle(String title){
        tvCenter.setVisibility(View.VISIBLE);
        tvCenter.setText(TextUtils.isEmpty(title)?" ":title);
        return this;
    }

    public TitlebarBuilder setLeftIcon(int res){
        tvLeft.setVisibility(View.GONE);
        ivLeft.setVisibility(View.VISIBLE);
        ivLeft.setBackgroundResource(res);
        return this;
    }

    public TitlebarBuilder setRightIcon(int res){
        tvRight.setVisibility(View.GONE);
        ivRight.setVisibility(View.VISIBLE);
        ivRight.setBackgroundResource(res);
        return this;
    }

    public TitlebarBuilder setLeftText(String title){
        ivLeft.setVisibility(View.GONE);
        tvLeft.setVisibility(View.VISIBLE);
        tvLeft.setText(title);
        return this;
    }

    public TitlebarBuilder setRightText(String title){
        ivRight.setVisibility(View.GONE);
        tvRight.setVisibility(View.VISIBLE);
        tvRight.setText(title);
        return this;
    }

    public TitlebarBuilder setBg(int color){
        mRootView.setBackgroundColor(color);
        return this;
    }

    public TitlebarBuilder setLeftTextClick(View.OnClickListener listener){
        tvLeft.setOnClickListener(listener);
        return this;
    }

    public TitlebarBuilder setRightTextClick(View.OnClickListener listener){
        tvRight.setOnClickListener(listener);
        return this;
    }

    public TitlebarBuilder setLeftIconClick(View.OnClickListener listener){
        ivLeft.setOnClickListener(listener);
        return this;
    }

    public TitlebarBuilder setRightIconClick(View.OnClickListener listener){
        ivRight.setOnClickListener(listener);
        return this;
    }

}
